//
//  LoadView.m
//  QianCheng
//
//  Created by 静静 on 16/3/21.
//  Copyright © 2016年 鼎商动力. All rights reserved.
//

#import "LoadView.h"

@interface LoadView()
{
    UIImageView       *_loadImageView;
    int               _angle;
}
@end

@implementation LoadView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createUI];
    }
    return self;
}

- (void)createUI
{
    _angle = 1.5;
//    self.layer.cornerRadius = 10;
//    self.layer.borderWidth = 1;
//    self.layer.borderColor = [UIColor colorWithHexString:@"888888" alpha:0.5].CGColor;
    self.backgroundColor = [UIColor clearColor];
    
    _loadImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 64, 60)];
    _loadImageView.centerX = self.width/2;
    _loadImageView.centerY = self.width/2;
    
    //执行动画
     [self tomAnimationOfName:@"loding_0" andCount:9];
     [self addSubview:_loadImageView];
//    [self startAnimation];
}

- (void)tomAnimationOfName:(NSString *) img andCount:(int)count
{
    //序列帧动画：让一组图片，和放电影一样，一张张的播放，动起来的效果
    
    //判断是否动画中，不可以同步
    if ([_loadImageView isAnimating]) {
        //直接结束动画操作方法,这里就是没有返回值，nil 不行
        return;
    }
    
    //开始肯定是存储图片，10个，用可变数组
    NSMutableArray *arrayImage = [NSMutableArray array];
    //遍历图片
    for (int i = 0; i < count ; i++) {
    
        NSString *name = [NSString stringWithFormat:@"%@%d", img, i];
        UIImage *image = [UIImage imageNamed:name];
        //添加到数组里
        [arrayImage addObject:image];
    }
    //然后开始动画
    //把图片放到animationImages,接受数组参数
    _loadImageView.animationImages = arrayImage;
    //设置时间间隔,10张图，图多就播的时间稍微长，否则短
    _loadImageView.animationDuration = arrayImage.count * 0.074;
    //设置重复次数(无线)
   _loadImageView.animationRepeatCount = 0;
    //开始动画
    [_loadImageView startAnimating];
    //结束动画
}


@end
